package com.jeeplus.modules.guide.service;

import com.alibaba.druid.sql.ast.statement.SQLForeignKeyImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jeeplus.database.datasource.annotation.DS;
import com.jeeplus.modules.guide.entity.MobileAreaType;
import com.jeeplus.modules.guide.mapper.RongYiBanMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@DS("queuing")
@Service
@RequiredArgsConstructor
@Slf4j
public class RongYiBanService {
    private final RongYiBanMapper rongYiBanMapper;
    /**
     * 对接大厅
     * @return
     */
    public List<Map<String,String>> establishSala(){
        return rongYiBanMapper.establishSala();
    }
    /**
     * 对接窗口
     * @return
     */
    public List<Map<String,String>> establishWindow(String hallguid){

        return rongYiBanMapper.establishWindow(hallguid);
    }

    /**
     *获取窗口对应的业务
     * @return
     */
    public List<Map<String, String>>  getWindowSerial(String hallguid){
        return rongYiBanMapper.getWindowSerial(hallguid);
    }
    /**
     * 创建事项分类
     * @return
     */
    public List<Map<String, String>>  establishSerialInfo(Map<String,String> map){

        return rongYiBanMapper.establishSerialInfo(map);
    }
    /**
     * 上传取号数据
     * @return
     */
    public Map<String,String> estabgetQueuingUp(Map<String,String> map){

        return rongYiBanMapper.estabgetQueuingUp(map);
    }
    /**
     * 上传取号数据是否取号
     * @return
     */
    public Map<String,String> estabgetIsCall(Map<String,String> map){

        return rongYiBanMapper.estabgetIsCall(map);
    }

    /**
     * 是否可以预约
     * @param map
     * @return
     */
    public int isAppointment(Map<String,String> map){
        int appointment = rongYiBanMapper.isAppointment(map);

        return appointment;
    }

    /**
     * 获取预约ID
     * @param map
     * @return
     */
    public String getAppointmentId(Map<String,String> map){

        return rongYiBanMapper.getAppointmentId(map);
    }

    /**
     * 删除预约
     * @return
     */
    public void delAppointment(String id){

        rongYiBanMapper.delAppointment(id);

    }
    /**
     * 获取大厅取号业务层级
     * @return
     */
    public List<Map<String,String>> getLevel(String levelId){

        return rongYiBanMapper.getLevel(levelId);
    }
    /**
     * 获取大厅业务
     * @return
     */
    public List<Map<String,String>> getBusiness(String levelId){

        return rongYiBanMapper.getBusiness(levelId);
    }
    /**
     * 按业务ID获取业务
     * @return
     */
    public Map<String,String> getSerialById(String Id){

        return rongYiBanMapper.getSerialById(Id);
    }

    /**
     * 按业务ID获取业务
     * @return
     */
    public Map<String,Object> isQuHao(String accountidcard,String itemid,String appointdate){

        return rongYiBanMapper.isQuHao(accountidcard,itemid,appointdate);
    }

    /**
     * 查询叫号状态调用几次
     * @return
     */
    public int isCall(String qno,String areacode){
        return  rongYiBanMapper.isCall(qno, areacode);
    }

    /**
     * 获取当天需上传取号的排队数据
     * @return
     */
    public List<Map<String,String>> toDayTakeNumber(){

        return rongYiBanMapper.toDayTakeNumber();
    }

    /**
     * 获取当天需上传叫号的排队数据
     * @return
     */
    public List<Map<String,String>> toDayCallNumber(){
        return rongYiBanMapper.toDayCallNumber();
    }
    /**
     * 获取当天需上传办结的排队数据
     * @return
     */
    public List<Map<String,String>> toDayFinishNumber(){
        return rongYiBanMapper.toDayFinish();
    }
    /**
     * 修改排叫号数据状态
     * @return
     */
    public void updateBak(String status,List<String> list){
        rongYiBanMapper.updateBak(status,list);
    }
    /**
     * 添加推送记录
     * @return
     */
    public void insertRongYiBanHistory(Map<String,String> map){
        rongYiBanMapper.insertRongYiBanHistory(map);
    }
    /**
     * 修改推送记录状态
     * @return
     */
    public void updateRongYiBanHistory(Map<String,String> map){
        rongYiBanMapper.updateRongYiBanHistory(map);
    }
    /**
     * 查询街道区划简称
     * @return
     */
    public String getJC(String sysno){
        return rongYiBanMapper.getJC(sysno);
    }

    /**
     * 根据业务ID获取业务
     * @return
     */
    public List<Map<String,String>> getYBJBusiness(String itemCode){
        return rongYiBanMapper.getYBJBusiness(itemCode);
    }
    /**
     * 预约排号查询
     * @return
     */
    public List<Map<String,String>> getYBJYY(String aac002,String isTakeNum){

        return rongYiBanMapper.getYBJYY(aac002,isTakeNum);
    }
    /**
     * 预约排号历史查询
     * @return
     */
    public List<Map<String,String>> getYBJAppointmentInfoHistory(String aac002,String isTakeNum,String isHandle,String pageIndex,String pageSize){
        PageHelper.startPage(Integer.parseInt(pageIndex+""), Integer.parseInt(pageSize+""));
        List<Map<String, String>> ybjAppointmentInfoHistory = rongYiBanMapper.getYBJAppointmentInfoHistory(aac002, isTakeNum, isHandle);
        PageInfo<Map<String,String>> pageInfo=new PageInfo<>(ybjAppointmentInfoHistory, HttpStatus.OK.value());
        if(Integer.parseInt(pageIndex+"")>pageInfo.getPages()){
            return new ArrayList<Map<String,String>>();
        }
        return pageInfo.getList();
    }

    public List<Map<String, Object>> getZoning(){
        List<Map<String, Object>> zoning = rongYiBanMapper.getZoning();
        return zoning;
    }
    public List<Map<String, Object>> getDepartment(){
        List< Map<String, Object>> lists=new ArrayList<>();
        List<String> department = rongYiBanMapper.getDepartment();
        for (int i = 0; i < department.size(); i++) {
            Map<String,Object> map=new HashMap<>();
            List<Map<String, String>> businessByDepartment = rongYiBanMapper.getBusinessByDepartment(department.get(i));
            map.put("name",department.get(i));
            map.put("gradeNameSet","分类");
            map.put("list",businessByDepartment);
            lists.add(map);
        }
        System.out.println(lists);
        return lists;
    }
    public List<Map<String,String>> getBusinessByZoning(String code){
        List<Map<String, String>> businessByZoning = rongYiBanMapper.getBusinessByZoning(code);
        return businessByZoning;
    }

}
